package com.controller;

import com.pojo.TbSupplier;
import com.service.SupplierService;
import com.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/supplier")
public class SupplierController {
    @Autowired
    JSONResult jsonResult;
    @Autowired
    SupplierService supplierService;

    @GetMapping("/findAllSupplierBySupplierName")
    public JSONResult findAllSupplierBySupplierName(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "supplierName",defaultValue = "-1") String supplierName){
        return supplierService.findAllSupplierBySupplierName(page,limit,supplierName);
    }
    @GetMapping("/findAllSupplier")
    public JSONResult findAllSupplier(@RequestParam("page") int page,@RequestParam("limit") int limit){
        return supplierService.findAllSupplier(page,limit);
    }

    @GetMapping("/findAllSupplierByState")
    public JSONResult findAllSupplierByState(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "state",defaultValue = "-1") int state){
        return supplierService.findAllSupplierByState(page,limit,state);
    }


    @PostMapping("/addSupplier")
    public JSONResult addUser(@RequestBody TbSupplier supplier){
        return supplierService.addSupplier(supplier);
    }


    @GetMapping("/deleteSupplier")
    public JSONResult deleteSupplier(@RequestParam("supplierId") int supplierId){
        return supplierService.deleteSupplier(supplierId);
    }


    @PostMapping("/updateSupplier")
    public JSONResult updateSupplier(@RequestBody TbSupplier supplier){
        return supplierService.updateSupplier(supplier);
    }


    @GetMapping("/findSupplierById")
    public JSONResult findSupplierById(@RequestParam("supplierId")int supplierId){
        return supplierService.findSupplierById(supplierId);
    }
}
